#include "MQTTClient.h"
#include <unistd.h>

int main(int argc, char const *argv[])
{
    // 主题1发送消息 主题2接收消息
    MQTTClient mqttClient("/mqtt/topic1", "/mqtt/topic2", 0);
    bool ok = mqttClient.connect("192.168.2.236", 1883);
    if (!ok)
    {
        return -1;
    }

#if 0
    while (1)
    {
        const char *msg = "hello world 1";
        mqttClient.send(msg, strlen(msg));
        sleep(1);
    }
#endif
    char buf[1024] = {0};
    while (1)
    {
        int ret = mqttClient.recv(buf, sizeof(buf));
        if (ret < 0)
        {
            fprintf(stderr, "Fail to recv\n");
            return -1;
        }
        buf[ret] = '\0';
        printf("Recv %d bytes :%s\n", ret, buf);
    }

    return 0;
}
